//
//  SelfHomeViewController.m
//  DefendHealth
//
//  Created by UNOHACHA on 17/2/18.
//  Copyright © 2017年 iMacOne. All rights reserved.
//

#import "SelfHomeViewController.h"
#import "SelfHomeModel.h"
#import "SelfHomeTabViewCell.h"
#import "MessageViewController.h"
#import "ChangeInfoViewController.h"
#import "HealthDataViewController.h"
#import "UserLoginVC.h"
@interface SelfHomeViewController ()
{
    NSArray *myArr;
}
@end

@implementation SelfHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
     self.TitleNav.text = @"我的";
    self.baseTableView.frame = CGRectMake(0, 64, WindowWidth, WindowHeight-49);
//    self.Nav.hidden = YES;
    self.TitleNav.hidden = YES;
    self.leftbutton.hidden = YES;
    myArr = @[@{@"title":@"我的活力"},
              @{@"title":@"健康数据"},
              @{@"title":@"我的收藏"},
              @{@"title":@"设置"},
              @{@ "title":@"关于"},];
    [self addHeadView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)addHeadView{
    UIView *headView1 = [UIView new];
    
    headView1.backgroundColor = [UIColor whiteColor];
   
    
    UIButton *messageBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(WindowWidth-10-26, 25, 26, 26)];
    [messageBtn1 addTarget:self action:@selector(message) forControlEvents:UIControlEventTouchUpInside];
    [messageBtn1 setBackgroundImage:[UIImage imageNamed:@"news-2"] forState:0];
    [self.Nav addSubview:messageBtn1];
    
    
    UIButton *kefuBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(WindowWidth-10-10-26-26, 26, 26, 26)];
    //    [messageBtn1 addTarget:self action:@selector(shenqingVip) forControlEvents:UIControlEventTouchUpInside];
    [kefuBtn1 setBackgroundImage:[UIImage imageNamed:@"customer-service-2"] forState:0];
    [self.Nav addSubview:kefuBtn1];
    
    UIImageView *touxiang = [UIImageView new];
    touxiang.frame = CGRectMake(10, 8, 50, 50);
    touxiang.layer.cornerRadius = 25;
    touxiang.layer.masksToBounds = YES;
    [headView1 addSubview:touxiang];
    touxiang.backgroundColor = [UIColor grayColor];
    
    UIButton *touxiangbtn1 = [[UIButton alloc] initWithFrame:CGRectMake(10, 3.5, 50, 50)];
    
    [touxiangbtn1 addTarget:self action:@selector(xiugaigerenxinxi) forControlEvents:UIControlEventTouchUpInside];
    [headView1 addSubview:touxiangbtn1];
    
    UILabel *nameLab1 = [UILabel new];
    nameLab1.frame = CGRectMake(kMaxX(touxiang.frame)+14, 70-60, 150, 15);
    nameLab1.text = @"MDK";
    nameLab1.font = FONT(15);
    nameLab1.textColor = UIColorFromRGB(0x000000);
    nameLab1.textAlignment = 0;
    [headView1 addSubview:nameLab1];
    
    UILabel *contentLab1 = [UILabel new];
    contentLab1.frame = CGRectMake(kMaxX(touxiang.frame)+14, kMaxY(nameLab1.frame)+14, 150, 10);
    contentLab1.text = @"天下无敌MDK";
    contentLab1.font = FONT(10);
    contentLab1.textColor = UIColorFromRGB(0x000000);
    contentLab1.textAlignment = 0;
    [headView1 addSubview:contentLab1];
    
    UILabel *fanNumlab1 = [UILabel new];
    fanNumlab1.frame = CGRectMake(WindowWidth-10-[ToolUtil autoWidth:@"999" width:599 height:12 num:12], 75-64, [ToolUtil autoWidth:@"999" width:599 height:12 num:12], 12);
    fanNumlab1.text = @"999";
    fanNumlab1.font = FONT(12);
    fanNumlab1.textColor = UIColorFromRGB(0x333333);
    fanNumlab1.textAlignment = 0;
    [headView1 addSubview:fanNumlab1];
    
    UILabel *fanlab1 = [UILabel new];
    fanlab1.frame = CGRectMake(kMaxX(fanNumlab1.frame)-[ToolUtil autoWidth:@"999" width:599 height:12 num:12], kMaxY(fanNumlab1.frame)+2, [ToolUtil autoWidth:@"粉丝" width:599 height:12 num:12], 12);
    fanlab1.text = @"粉丝";
    fanlab1.font = FONT(12);
    fanlab1.textColor = UIColorFromRGB(0x333333);
    fanlab1.textAlignment = 0;
    [headView1 addSubview:fanlab1];
    
    UILabel *focusNumlab1 = [UILabel new];
    focusNumlab1.frame = CGRectMake(WindowWidth-10-[ToolUtil autoWidth:@"999" width:599 height:12 num:12]-25-[ToolUtil autoWidth:@"999" width:599 height:12 num:12], 75-64, [ToolUtil autoWidth:@"999" width:599 height:12 num:12], 12);
    focusNumlab1.text = @"999";
    focusNumlab1.font = FONT(12);
    focusNumlab1.textColor = UIColorFromRGB(0x333333);
    focusNumlab1.textAlignment = 0;
    [headView1 addSubview:focusNumlab1];
    
    UILabel *focuslab1 = [UILabel new];
    focuslab1.frame = CGRectMake(kMaxX(focusNumlab1.frame)-[ToolUtil autoWidth:@"999" width:599 height:12 num:12], kMaxY(fanNumlab1.frame)+2, [ToolUtil autoWidth:@"关注" width:599 height:12 num:12], 12);
    focuslab1.text = @"关注";
    focuslab1.font = FONT(12);
    focuslab1.textColor = UIColorFromRGB(0x333333);
    focuslab1.textAlignment = 0;
    [headView1 addSubview:focuslab1];
    
    UIView *hui = [UIView new];
    hui.frame = CGRectMake(0, 132-64,WindowWidth , 1.5);
    hui.backgroundColor = kLineColor;
    [headView1 addSubview:hui];
    
    UILabel *dynamicLab1 = [UILabel new];
    dynamicLab1.frame = CGRectMake(0, kMaxY(hui.frame)+12.5, kMaxX(touxiang.frame), 12);
    dynamicLab1.text = @"动态";
    dynamicLab1.font = FONT(12);
    dynamicLab1.textColor = UIColorFromRGB(0x333333);
    dynamicLab1.textAlignment = 1;
    [headView1 addSubview:dynamicLab1];
    
    UILabel *dynamicNumLab1 = [UILabel new];
    dynamicNumLab1.frame = CGRectMake(0, kMaxY(dynamicLab1.frame)+4, kMaxX(touxiang.frame), 30);
    dynamicNumLab1.text = @"12";
    dynamicNumLab1.font = [UIFont systemFontOfSize:30 weight:10];
    dynamicNumLab1.textColor = UIColorFromRGB(0x333333);
    dynamicNumLab1.textAlignment =1;
    [headView1 addSubview:dynamicNumLab1];
    
    for (int i = 0; i<4; i++) {
        UIImageView *img = [UIImageView new];
        img.frame = CGRectMake(kMaxX(touxiang.frame)+(WindowWidth-30-kMaxX(touxiang.frame))/4*i+6*(i+1), kMaxY(hui.frame)+12.5, (WindowWidth-30-kMaxX(touxiang.frame))/4, 61);
        img.backgroundColor = [UIColor grayColor];
        [headView1 addSubview:img];
        
    }
    
    UIView *hui2 = [UIView new];
    hui2.frame = CGRectMake(0, kMaxY(hui.frame)+86,WindowWidth , 5);
    hui2.backgroundColor = k_TableBackColor;
    [headView1 addSubview:hui2];
    
    headView1.frame = CGRectMake(0, 0,WindowWidth , kMaxY(hui2.frame));
    self.baseTableView.tableHeaderView = headView1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return myArr.count;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 2) {
        return 50;
    }
    else{
    return 47;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString * cellIden = @"cell";
    SelfHomeTabViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIden];
    if (cell == nil) {
        cell = [[SelfHomeTabViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIden];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.backgroundColor = [UIColor whiteColor];
    SelfHomeModel *model = [[SelfHomeModel alloc] initWithDictionary:myArr[indexPath.row]];
    cell.model = model;
    if (indexPath.row == 2) {
        cell.hui.frame = CGRectMake(0, 45, WindowWidth, 5);
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 1) {
        HealthDataViewController *stVC = [HealthDataViewController new];
        stVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:stVC animated:YES];

    }
    if (indexPath.row == 3) {
        UserLoginVC *stVC = [UserLoginVC new];
        stVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:stVC animated:YES];
        
    }
}
#pragma mark - 消息界面
-(void)message{
    MessageViewController *stVC = [MessageViewController new];
    stVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:stVC animated:YES];
}
#pragma mark - 修改个人信息
-(void)xiugaigerenxinxi{
    ChangeInfoViewController *stVC = [ChangeInfoViewController new];
    stVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:stVC animated:YES];

}
@end
